package top.datacluster.basic.sort;

public class QuickSort {

    public void sort(int[] nums){
        quick(nums, 0, nums.length - 1);

    }

    public void quick(int[] nums, int start, int end){
        if (start > end){
            return;
        }
        int flag = nums[start];
        int left = start;
        int right = end;

        while (left < right){
            while (left < right && flag < nums[right]){
                right--;
            }
            int temp = nums[left];
            nums[left] = nums[right];
            nums[right] = temp;

            while (left < right && flag > nums[left]){
                left++;
            }
            temp = nums[right];
            nums[right] = nums[left];
            nums[left] = temp;
        }
        quick(nums, start, left - 1);
        quick(nums, left + 1, end);
    }

    public static void main(String[] args) {
        int[] test = new int[]{8, 4, 9, 1, 10, 6};
        new QuickSort().sort(test);
        for (int i : test){
            System.out.print(i + " ");
        }
    }
}
